angular.module('app')
            .directive('imageModel', ['$parse', function ($parse) {
                return {
                    restrict: 'A',
                    scope: true,
                    link: function(scope, element, attrs, ngModel) {
                        var model = $parse(attrs.imageModel);
                        var modelSetter = model.assign;
                        element.bind('change', function(event){
                            scope.$apply(function(){
                                modelSetter(scope, element[0].files[0]);
                            });
                            //附件预览
                            scope.imgFile = (event.srcElement || event.target).files[0];
                            scope.getFile(scope.imgFile);
                        });
                    }
                };
            }]);